﻿<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="com.mr.qa.GlobalConfigs"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/sharedfilecategory.tld" prefix="sfcat"%>
<%@ taglib uri="/WEB-INF/qautil.tld" prefix="qautil"%>
<script type="text/javascript" src="<%=request.getContextPath()%>/qa/js/catselect.js"></script>
<div style="padding:0 0 2px 0;">
    <html:link page="/sf.mrqa?action=list">MFer 资料</html:link><sfcat:insert resultKind="navilinks"/>
</div>
<c:set var="sfid" value="${sharedfile.id}"/>
<div style="background-color:#FAFCFC;width:100%;padding:4px 4px 4px 4px;border:1px solid #ccc;">
    <table cellpadding="0" cellspacing="0" border="0" style="width:710;word-wrap:break-word;table-layout:fixed;">
        <tr>
            <td width="145" valign="top">
            	<table border="0">
            		<tr>
            			<td valign="top">
            				<c:choose>
											<c:when test="${sharedfile.mrIaskUser.headerImage == null}" >
												<img src="qa/images/header_default50.jpg" width="50" height="50">
											</c:when>
											<c:otherwise>
												<html:img page="header${sharedfile.mrIaskUser.headerImage}" width="50" height="50"/>
											</c:otherwise>
										</c:choose>
            			</td>
            		</tr>
            	</table>
                <c:set var="user_id" value="${sharedfile.mrIaskUser.id}"/><html:link page="/user.mrqa?action=viewuserbyother" styleId="author" paramId="id" paramName="user_id"><b><c:out value="${sharedfile.mrIaskUser.loginName}"/></b></html:link>
                <br>
                <c:out value="${sharedfile.mrIaskUser.userScore.title}"/>
                <br>
                <br>
            </td>
            <td valign="top">
                <div style="padding-bottom:10px;">
                    <span style="float:left;"><img src="qa/images/sharedfile.gif" alt="共享资料" align="middle"/>&nbsp;&nbsp;<b><c:out value="${sharedfile.name}" escapeXml="false"/></b></span>
                    <span style="float:right;">
                       <!--<a href="#" onclick="icomment(this);">评论</a>-->
                       <c:if test="${user_session.type == '1'}">
                            <c:if test="${sharedfile.isRecommended == true}">
                                <img src="qa/images/mr-qa-recommend-icon.gif" border="0" alt="取消推荐" align="absbottom"/>&nbsp;<html:link page="/sf.mrqa?action=recommend" paramId="id" paramName="sfid">取消推荐</html:link>
                            </c:if>
                            <c:if test="${sharedfile.isRecommended == false}">
                                <img src="qa/images/mr-qa-recommend-icon.gif" border="0" alt="推荐" align="absbottom"/>&nbsp;<html:link page="/sf.mrqa?action=recommend" paramId="id" paramName="sfid">推荐</html:link>
                            </c:if>
                        </c:if>
                    </span>
                </div>
                <br>
                <pre style="white-space: pre-wrap;"><c:out escapeXml="false" value="${fn:replace(sharedfile.description,'<image=','<img name=contentimg border=0 src=')}"/></pre>
                <br>
            </td>
        </tr>
        <tr>
            <td>
                <fmt:formatDate value="${sharedfile.postDate}" var="postDate" type="both" pattern="yyyy-MM-dd HH:mm:ss"/>
                <c:out value="${postDate}"/>
            </td>
            <td>
                <div>
                    <span style="float:left;">
                    <c:choose>
									    <c:when test="${needMoney != null}">
                        <img src="qa/images/download-sharedfile.gif" alt="登录用户才能下载,下载一次积分减少<%=GlobalConfigs.SHARED_FILE_MONEY%>分" border="0" align="absbottom">
                    		&nbsp;&nbsp;文件类型:<c:out value="${sharedfile.fileType}"/>
                    		&nbsp;&nbsp;大小:<fmt:formatNumber type="number" value="${sharedfile.size/1024}" pattern="0.00"/>K
                    		&nbsp;&nbsp;下载:<c:out value="${sharedfile.downloadCount}"/><br>
                    		<font color="red">您的当前积分小于<%=GlobalConfigs.SHARED_FILE_MONEY%>分，无法下载</font>
									    </c:when>
									    <c:when test="${registerInterval != null}">
                        <img src="qa/images/download-sharedfile.gif" alt="登录用户才能下载,下载一次积分减少<%=GlobalConfigs.SHARED_FILE_MONEY%>分" border="0" align="absbottom">
                    		&nbsp;&nbsp;文件类型:<c:out value="${sharedfile.fileType}"/>
                    		&nbsp;&nbsp;大小:<fmt:formatNumber type="number" value="${sharedfile.size/1024}" pattern="0.00"/>K
                    		&nbsp;&nbsp;下载:<c:out value="${sharedfile.downloadCount}"/><br>
                    		<font color="red">新用户注册后<%=GlobalConfigs.INTERVAL_REGISTER_DOWNLOAD%>小时才能下载共享资料</font>
									    </c:when>
									    <c:when test="${disableDownload == true}">
                        <img src="qa/images/download-sharedfile.gif" alt="登录用户才能下载,下载一次积分减少<%=GlobalConfigs.SHARED_FILE_MONEY%>分" border="0" align="absbottom">
                    		&nbsp;&nbsp;文件类型:<c:out value="${sharedfile.fileType}"/>
                    		&nbsp;&nbsp;大小:<fmt:formatNumber type="number" value="${sharedfile.size/1024}" pattern="0.00"/>K
                    		&nbsp;&nbsp;下载:<c:out value="${sharedfile.downloadCount}"/><br>
                    		<font color="red">您每天只能下载<%=GlobalConfigs.NUMBER_SHARED_FILE_A_USER_DOWNLOAD_ONE_DAY%>个共享资料</font>
									    </c:when>
									    <c:when test="${user_session.active != true}">
                        <img src="qa/images/download-sharedfile.gif" alt="登录用户才能下载,下载一次积分减少<%=GlobalConfigs.SHARED_FILE_MONEY%>分" border="0" align="absbottom">
                    		&nbsp;&nbsp;文件类型:<c:out value="${sharedfile.fileType}"/>
                    		&nbsp;&nbsp;大小:<fmt:formatNumber type="number" value="${sharedfile.size/1024}" pattern="0.00"/>K
                    		&nbsp;&nbsp;下载:<c:out value="${sharedfile.downloadCount}"/><br>
                    		<font color="red">您的帐户未激活，不能下载</font>
									    </c:when>
									    <c:otherwise>
									    	<a href="<%=request.getContextPath()%>/sharedfile<c:out value="${sharedfile.path}"/>">
                        	<img src="qa/images/download-sharedfile.gif" alt="登录用户才能下载,下载一次积分减少<%=GlobalConfigs.SHARED_FILE_MONEY%>分" border="0" align="absbottom">
                    		</a>
                    		&nbsp;&nbsp;文件类型:<c:out value="${sharedfile.fileType}"/>
                    		&nbsp;&nbsp;大小:<fmt:formatNumber type="number" value="${sharedfile.size/1024}" pattern="0.00"/>K
                    		&nbsp;&nbsp;下载:<c:out value="${sharedfile.downloadCount}"/>
									    </c:otherwise>
										</c:choose>
                    </span>
                    <span style="float:right;">
                       <c:if test="${user_session.userId == sharedfile.mrIaskUser.id and user_session.type != '1'}">
                            <a href="#modifyanchor" onclick="modifySharedFile();return false;" title=" 修改共享资料">修改</a>
                       </c:if>
                       <c:if test="${user_session.type == '1'}">
                        <a href="#modifycatanchor" onclick="changeSharedFileCat();return false;" title="改变资料分类">转移</a>
                        &nbsp;|&nbsp;
                        <c:if test="${sharedfile.state == '0'}">
                            <html:link page="/sf.mrqa?action=hide" paramId="id" paramName="sfid">隐藏</html:link>
                        </c:if>
                        <c:if test="${sharedfile.state == '1'}">
                            <html:link page="/sf.mrqa?action=hide" paramId="id" paramName="sfid">取消隐藏</html:link>
                        </c:if>
                            &nbsp;|&nbsp;
                            <a href="#modifyanchor" onclick="modifySharedFile();return false;" title=" 修改共享资料">修改</a>
                        &nbsp;|&nbsp; 
                        <html:link page="/sf.mrqa?action=confirmdelete" paramId="id" paramName="sfid" title="删除后不能恢复">删除</html:link>
                        </c:if>
                    </span>
                </div>
                <br>
            </td>
        </tr>    
    </table>
</div>
<c:if test="${user_session.userId == sharedfile.mrIaskUser.id or user_session.type == '1'}">
    <a name="modifyanchor"/>
    <div id="sharedFileDiv" style="display:none;">
        <br>
        <table class="mars" cellpadding="0" cellspacing="0">
            <html:form action="/sf" method="post" enctype="multipart/form-data" onsubmit="return validatesf(this);">
            <html:hidden property="action" value="modify"/>
            <input type="hidden" name="id" value="<c:out value="${sharedfile.id}"/>"/>
            <tr class="even">
                <td colspan="2" align="left"><b>修改共享资料</b></td>
            </tr>
            <tr>
                <td align="right">附件</td>
                <td>
                   原文件:<a href="<%=request.getContextPath()%>/sharedfile<c:out value="${sharedfile.path}"/>">
                                <c:out value="${sharedfile.name}"/>
                    </a>
                    <hr>            
                    <html:file property="file" size="70" onchange="fileChanged(this);"/><br>(重新选择文件上载后原文件被覆盖,文件大小不能超过5M.)
                </td>
            </tr>
            <tr class="even">
                <td align="right">名称</td>
                <td>
                    <html:text property="name" size="70" maxlength="40" name="sharedfile"/>*(最长40个字符;如果不填写，默认为上载文件名字)
                </td>
            </tr> 
        <tr>
            <td align="right">描述</td>
            <td>
                <html:textarea property="description" cols="50" rows="5" name="sharedfile"/>(可输入100个汉字)
            </td>
        </tr>
        <tr class="even">
            <td align="right">图片</td>
            <td>
                <iframe name="ad1" frameborder="0" width="100%" height="25" scrolling="no" src="/question.mrqa?action=uploadImage&imageIn=sf&imageArea=sharedFile[1].description"></iframe>
            </td>
        </tr>
        <tr>
            <td align="right"></td>
            <td>
                <input type="submit" value="保存共享资料"/>&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="取消" onclick="modifySharedFile();"/>
            </td>
        </tr>
        </html:form>
        </table>
    </div>
    <script type="text/javascript">
    /**
    *the file name changes according to selected local file
    */
    function fileChanged(pFile)
    {
        var name = pFile.form.name.value;
        if(name.length > 0)return;
        var fileName = pFile.value;
        var slashLastIndex = fileName.lastIndexOf("\\");
        var dotIndex = fileName.lastIndexOf(".");
        var shortFileName = fileName.substring(slashLastIndex+1,dotIndex);
        pFile.form.name.value=shortFileName;
    }

    /**
    *dispaly or open the div for displaying the form of question for modifying
    */
    function modifySharedFile()
    {
        var sharedFileDiv = document.getElementById("sharedFileDiv");
        if(sharedFileDiv.style.display == "none")
        {
            sharedFileDiv.style.display = "block";
            var sharedFileForms = document.sharedFile;
            var sharedFileForm;
            for(var i=0;i<sharedFileForms.length;i++)
            {
                sharedFileForm = sharedFileForms[i];
                if(sharedFileForm.action != null && sharedFileForm.action.value == "modify")
                {
                  sharedFileForm.name.focus();
                  break;
                }
            }
            //self.scrollTo(document.body.scrollWidth,document.body.scrollHeight/2);
            document.location.hash = "#modifyanchor";
        }
        else
            sharedFileDiv.style.display = "none";
        return false;
    }
    function validatesf(pForm)
    {
            if(pForm.name.value.length < 2)
            {
                alert("[名称]必须大于2个字符");
                pForm.name.focus();
                return false;
            }
            else if(pForm.name.value.length > 40)
            {
                alert("[名称]最长40个字符");
                pForm.name.focus();
                return false;
            }
            
            var uploadImage = frames["ad1"].window.document.getElementById("uploadButton");
        		if(uploadImage){
    					uploadImage.disabled = true;
    				}

        return true;
    }
</script>
</c:if>
<c:if test="${user_session.type == '1'}">
    <xml id="catsData">
          <cats id="cats">  
            <sfcat:insert resultKind="dropdown"/>
          </cats>
    </xml>
    <a name="modifycatanchor"/>
    <div id="changeSharedFileCatDiv" style="display:none;">
        <br>
        <table class="mars" cellpadding="0" cellspacing="0">
            <html:form action="/sf" method="post" onsubmit="return validateChangSharedFileCatForm(this);">
            <html:hidden property="action" value="changecat"/>
            <input type="hidden" name="id" value="<c:out value="${sharedfile.id}"/>"/>
            <input type="hidden" name="catId" value="<c:out value="${sharedfile.mrIaskSharedFileCategory.id}"/>"/>
            <tr class="even">
                <td colspan="2" align="left"><b>转移共享资料</b></td>
            </tr>
            <tr>
                <td align="right">分类</td>
                <td valign="top">
                    <html:select property="cat1Id" multiple="true" size="15" onchange="selectedCat1Changed(this)">
                    </html:select>
                    <html:select property="cat2Id" multiple="true" size="15" onchange="selectedCat2Changed(this)">
                        <html:option value="">选择分类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</html:option>
                    </html:select>
                    <html:select property="cat3Id" multiple="true" size="15">
                        <html:option value="">选择分类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</html:option>
                    </html:select>*
                </td>
            </tr>
            <tr class="even">
                <td align="right"></td>
                <td>
                    <input type="submit" value="转 移"/>&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="取消" onclick="changeSharedFileCat();"/>
                </td>
            </tr>
            </html:form>
        </table>
    <!-- change cat -->
    <script type="text/javascript">
        var sharedFileForms = document.sharedFile;
        var actionCode;
        var sharedFileForm;
        for(var i=0;i<sharedFileForms.length;i++)
        {
            actionCode = sharedFileForms[i].action.value;
            if(actionCode == "changecat")
            {
                sharedFileForm = sharedFileForms[i];
                break;
            }
        }
        try
        {
            if(sharedFileForm != null)
            {
                initSelect1ForSF(sharedFileForm);
            }
        }
        catch(err)
        {
            alert("初始化资料分类出现异常："+err);
        }
        function changeSharedFileCat()
        {
            var changeSharedFileCatDiv = document.getElementById("changeSharedFileCatDiv");//changeSharedFileCatDiv
            if(changeSharedFileCatDiv.style.display == "none")
            {
                changeSharedFileCatDiv.style.display = "block";
                var sharedFileForms = document.sharedFile;
                for(var i=0;i<sharedFileForms.length;i++)
                {
                    if(sharedFileForms[i].action.value == "changecat")
                    {
                      sharedFileForms[i].cat1Id.focus();
                      break;
                    }
                }
                //self.scrollTo(document.body.scrollWidth,document.body.scrollHeight);
                document.location.hash = "#modifycatanchor";
            }
            else
                changeSharedFileCatDiv.style.display = "none";
            return false;
        }
        function validateChangSharedFileCatForm(pForm)
        {
            var selectedCatIdValue = getSelectedCatIdValue(pForm);
            if(selectedCatIdValue == "")
            {
                alert("[分类]必须选择");
                return false;
            }
            pForm.catId.value = selectedCatIdValue;
            return true;    
        }
    </script>
  </div>  
</c:if>
          <!--comment -->
          <c:if test="${fn:length(sharedfile.comments) > 0}">
          <br>
            <div>
                <span style="float:left;" class="title1">相关评论</span>
                <span style="float:right;cursor:hand;color:red" onclick="expandComments();" id="commentsDivOpenIndicator" title="关闭"><img id="commentImgSwitchor" src="qa/images/ico_collapse.gif"/></span>
            </div>
          <div id="commentsDiv" style="background-color:#FAFCFC;width:720;padding:4px 4px 4px 4px;border:1px solid #ccc;">
        <c:if test="${param.page == null}">
            <c:set var="page" value="1" scope="request"/>
        </c:if>
        <c:if test="${param.page != null}">
            <c:set var="page" value="${param.page}" scope="request"/>
        </c:if>
        <c:if test="${param.page == 0}">
            <c:set var="page" value="1" scope="request"/>
        </c:if>
        <c:if test="${param.pageSize == null}">
            <c:set var="pageSize" value="6" scope="request"/>
        </c:if>
        <c:if test="${param.pageSize != null}">
            <c:set var="pageSize" value="${param.pageSize}" scope="request"/>
        </c:if>
        <c:set var="resultSize" value="${fn:length(sharedfile.comments)}" scope="request"/>
        <c:set var="begin" value="${(page-1)*pageSize}"/>
        <c:set var="end" value="${page*pageSize-1}"/>
            <c:forEach var="comment" items="${sharedfile.comments}" begin="${begin}" end="${end}">
                <table cellpadding="0" cellspacing="0" border="0" style="width:710;word-wrap:break-word;table-layout:fixed;">
                   <tr>
                    <td width="145" valign="top">
                    	<table border="0">
            						<tr>
            							<td valign="top">
            								<c:choose>
															<c:when test="${comment.mrIaskUser.headerImage == null}" >
																<img src="qa/images/header_default50.jpg" width="50" height="50">
															</c:when>
															<c:otherwise>
																<html:img page="header${comment.mrIaskUser.headerImage}" width="50" height="50"/>
															</c:otherwise>
														</c:choose>
            							</td>
            						</tr>
            					</table>
                        <c:set var="user_id" value="${comment.mrIaskUser.id}"/>
                        <html:link page="/user.mrqa?action=viewuserbyother" styleId="author" paramId="id" paramName="user_id"><b><c:out value="${comment.mrIaskUser.loginName}"/></b></html:link>
                        <br>
                        <c:out value="${comment.mrIaskUser.userScore.title}"/>
                        <br>
                        <br>
                        <fmt:formatDate value="${comment.postDate}" var="postDate" type="both" pattern="yyyy-MM-dd HH:mm:ss"/>
                        <c:out value="${postDate}"/>
                    </td>
                    <td valign="top">
                        <pre style="white-space: pre-wrap;"><c:out value="${fn:replace(comment.content,'<image=','<img name=contentimg border=0 src=')}" escapeXml="false"/></pre>
                    </td>
                   </tr>
                   <tr>
                        <td>&nbsp;</td>
                        <td align="right">
                            <div>
                                <span style="float:left">
                                     <c:if test="${comment.mrIaskUser.signature != ''}">
                                        个人签名:&nbsp;&nbsp;<font color="blue"><c:out value="${comment.mrIaskUser.signature}"/></font>
                                    </c:if>&nbsp;
                                </span>    
                                <span style="float:right">
                                    <c:if test="${user_session.userId == comment.mrIaskUser.id or user_session.type == '1'}">
                                        <html:link page="/comment.mrqa?action=delete" paramId="id" paramName="comment" paramProperty="id" title="删除评论后不能恢复">
                                        删除</html:link>
                                    </c:if>
                                </span>                                
                        </td>
                   </tr>
                </table>
                <hr> 
                </c:forEach>
            </div>
                <script type="text/javascript">
                    function expandComments()
                    {
                        var commentsDiv = document.getElementById("commentsDiv");
                        var commentsDivOpenIndicator = document.getElementById("commentsDivOpenIndicator");
                        var imgSwitchor = document.getElementById("commentImgSwitchor");
                        if(commentsDiv.style.display == "none")
                        {
                            commentsDiv.style.display = "block";
                            commentImgSwitchor.src = "qa/images/ico_collapse.gif";
                            commentsDivOpenIndicator.title = "关闭";
                        }
                        else
                        {
                            commentsDiv.style.display = "none";
                            commentImgSwitchor.src = "qa/images/ico_expand.gif";
                            commentsDivOpenIndicator.title = "展开";
                        }
                    }
                </script>
            </c:if>
            <!-- pagination -->
            <div align="center"><qautil:page action="/sf.mrqa"/></div>
                <!--comment form-->
                <br>
                <table border="0" cellpadding="0" cellspacing="0" align="center" width="720">
                    <tr style="background:url(qa/images/dothline.gif) bottom;">
                        <td width="720">
                        &nbsp;&nbsp;&nbsp;&nbsp;<b>我来评论</b>
                        </td>
                    </tr>
                </table>
                <div style="width:721;padding:12px 4px 4px 4px;border-left:1px dotted #ccc;border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;">
                    <table align="center" width="100%" cellpadding="0" cellspacing="0">
                         <html:form action="/comment" onsubmit="return commentValidate(this);">
                            <html:hidden property="action" value="add"/>
                            <html:hidden property="subjectType" value="S"/>
                            <input type="hidden" name="subjectId" value="<c:out value="${sharedfile.id}"/>"/>
                        <tr>
                            <td align="left" width="150" valign="top">&nbsp;&nbsp;&nbsp;&nbsp;内容:<a name="comment">&nbsp;</a></td>
                            <td><html:textarea property="content" cols="75" rows="4"/>*</td>
                        </tr>
                        <tr>
                            <td colspan="2" height="12" align="right">可输入100个汉字&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                        </tr>
                         <tr>
                            <td align="left" width="150" valign="top">&nbsp;&nbsp;&nbsp;&nbsp;图片:<a name="comment">&nbsp;</a></td>
                            <td><iframe name="ad" frameborder="0" width="100%" height="25" scrolling="no" src="/question.mrqa?action=uploadImage&imageIn=sfcomment&imageArea=commentf.content"></iframe></td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td><input type="submit" value="提交评论"/>(*必填项)</td>
                        </tr>
                        </html:form>
                    </table>    
                </div>
                         <script type="text/javascript">
                         	    /*function checkDownload(){
                         	    	<c:if test="${user_session.userId != sharedfile.mrIaskUser.id}">
                         	    	if(!confirm("此次操作将扣除<%=GlobalConfigs.SHARED_FILE_MONEY%>分积分，确定要下载么？"))
    														return false;
                         	    	</c:if>
    													}*/
                            function icomment(pLink)
                            {
                                /*
                                var commentDiv = document.getElementById("commentdiv");
                                if(commentDiv.style.display == "none")
                                    commentDiv.style.display = "block";
                                else
                                    commentDiv.style.display = "none";
                                    */
                                //alert(document.commentf.content.name);
                                window.scrollTo(document.body.scrollWidth,document.body.scrollHeight);
                                document.commentf.content.focus();    
                                return false;
                            }
                            function commentValidate(pForm)
                            {
                                var content = pForm.content.value;
                                if(content == "" || content.length < 2)
                                {
                                    alert("[评论]必须填写，必须大于2个字符");
                                    return false;
                                }
                                
                                var uploadImage = frames["ad"].window.document.getElementById("uploadButton");
        												if(uploadImage){
    															uploadImage.disabled = true;
    														}
                                return true;
                            }
                         </script>
